package com.atguigu.myjuc.block;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * 阻塞队列提供以下**4种处理方法**：
 *
 * |                  | 抛出异常  | 特殊值   | 阻塞   | 超时                 |
 * | ---------------- | --------- | -------- | ------ | -------------------- |
 * | **插入**         | add(e)    | offer(e) | put(e) | offer(e, time, unit) |
 * | **移除**         | remove()  | poll()   | take() | poll(time, unit)     |
 * | **检查（获取）** | element() | peek()   | 不可用 | 不可用               |
 */
public class BlockingQueueDemo {
    public static void main(String[] args) throws InterruptedException {
        //创建阻塞队列
        BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);//容量3

        /*System.out.println(blockingQueue.add("a"));
        System.out.println(blockingQueue.add("b"));
        System.out.println(blockingQueue.add("c"));
        //System.out.println(blockingQueue.add("d"));超过最大数三个报异常
        System.out.println(blockingQueue.element());

        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());*/

       /* System.out.println(blockingQueue.offer("a"));
        System.out.println(blockingQueue.offer("b"));
        System.out.println(blockingQueue.offer("c"));

        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.peek());*/

        /*blockingQueue.put("a");
        blockingQueue.put("b");
        blockingQueue.put("c");
        //blockingQueue.put("d");
        System.out.println("11111" + "\t"+blockingQueue.size());
        System.out.println(blockingQueue.take());
        System.out.println(blockingQueue.take());
        System.out.println(blockingQueue.take());*/


        /*System.out.println(blockingQueue.offer("a",2,5));*/
    }
}
